package ru.rchervot.sanasar.client.view;

import ru.rchervot.sanasar.client.event.EventUISectionsWidthChange;
import ru.rchervot.sanasar.client.model.UserSettings;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;

public abstract class AbstractModuleSearchPresenter extends
		AbstractModulePresenter implements ModuleSearchPresenter {
	
	
	protected abstract void addHandlerNewRecord();
	
	public AbstractModuleSearchPresenter(ModuleSearchPresenterDisplay display,
			HandlerManager eventBus,
			UserSettings settings) {
		
		super(display, eventBus, settings);
		
		addHandlerNewRecord();
		addHandlerCollapsible();
	}
	
	protected ModuleSearchPresenterDisplay getDisplay() {
		return (ModuleSearchPresenterDisplay)display;
	}
	
	public void addHandlerCollapsible() {
		getDisplay().getCollapsibleButton().addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				if (getDisplay().isCollapsibleCollapsed()) {
					eventBus.fireEvent(EventUISectionsWidthChange.build(Constants.kSectionsWidth));
				} else {
					eventBus.fireEvent(EventUISectionsWidthChange.build(Constants.kSectionsWidthCollapsed));
				}
			}
		});
	}
	
	
	
}
